import React from 'react';
import { StyleSheet, View, Text, TouchableOpacity, useColorScheme } from 'react-native';
import SearchNoteCard from './SearchNoteCard';

// 定义 MyNoteCard 的 props 类型
interface MyNoteCardProps {
  noteId: number;
  imageUrl: string;
  title: string;
  content: string;
  authorAvatarUrl: string;
  authorId: string;
  viewCount: number;
  auditStatus: 0 | 1 | 2;
  onDelete: () => void;
  onEdit: () => void;
  navigation: any; // 添加 navigation 属性
}

const MyNoteCard: React.FC<MyNoteCardProps> = ({
  noteId,
  imageUrl,
  title,
  content,
  authorAvatarUrl,
  authorId,
  viewCount,
  auditStatus,
  onDelete,
  onEdit,
  navigation,
}) => {
  const colorScheme = useColorScheme();
  const isDarkMode = colorScheme === 'dark';
  const auditStatusText = {
    0: '审核中',
    1: '成功',
    2: '失败'
  }[auditStatus];

  const auditStatusColor = {
    0: 'orange',
    1: 'green',
    2: 'red'
  }[auditStatus];

  return (
    <View style={styles.container}>
      <SearchNoteCard
        noteId={noteId}
        imageUrl={imageUrl}
        title={title}
        content={content}
        authorAvatarUrl={authorAvatarUrl}
        authorId={authorId}
        viewCount={viewCount}
      />
      <View style={styles.statusAndButtons}>
        <Text style={[styles.auditStatusText, { color: auditStatusColor }]}>审核状态：{auditStatusText}</Text>
        <View style={styles.buttonContainer}>
          <TouchableOpacity onPress={onDelete} style={styles.button}>
            <Text style={styles.buttonText}>删除</Text>
          </TouchableOpacity>
          <TouchableOpacity onPress={onEdit} style={styles.button}>
            <Text style={styles.buttonText}>编辑</Text>
          </TouchableOpacity>
        </View>
      </View>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    borderColor: '#666',
    borderWidth: 1,
    borderRadius: 10,
  },
  statusAndButtons: {
    flexDirection: 'row',
    justifyContent: 'space-between',
    alignItems: 'center',
    padding: 10,
  },
  auditStatusText: {
    fontSize: 14,
  },
  buttonContainer: {
    flexDirection: 'row',
  },
  button: {
    marginLeft: 10,
    paddingHorizontal: 15,
    paddingVertical: 5,
    backgroundColor: '#007AFF',
    borderRadius: 5,
  },
  buttonText: {
    color: '#fff',
    fontSize: 14,
  },
});

export default MyNoteCard;
